// pages/detection/index.js
const app = getApp();
var config = require('../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: config.imgPath,
    proInfo:{},
    jieguoList:[]
  },

  addFavorite:function () {
    let self = this
    app.request({
      url: 'api/UserCenter/addFavorite',
      method: "GET",
      data:{productId:self.data.proInfo.Id},
      success: function (res) {
        self.setData({
          isfavoter:true
        })
      }
    })
  },
  deleteFavorite:function (e) {
    var productId = this.data.proInfo.Id
    let self = this
    app.request({
      url: 'api/UserCenter/deleteFavorite',
      method: "GET",
      data:{productId:productId},
      success: function (res) {
        self.setData({
          isfavoter:false
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.editTabbar();
    this.loadInfo(options.id)
  },

  loadInfo(id) {
    let self = this
    app.request({
      url: 'api/product/getProductById',
      method: "GET",
      data:{id:id},
      success: function (res) {
        if (res.data != null) {
          var pro = res.data.proinfo
          if(pro.content12 != null){
            pro.content12 = pro.content12.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content11 != null){
            pro.content11 = pro.content11.replace(/<img/g, '<img class="richImg"')
          }
          if(pro.content10 != null){
          pro.content10 = pro.content10.replace(/<img/g, '<img class="richImg"')
          }
            self.setData({
              proInfo: pro,
              isfavoter:res.data.isfavoter
            })


            app.request({
              url: 'api/product/getaclist',
              method: "GET",
              data:{id:self.data.proInfo.Id,name:"检测结果"},
              success: function (res) {
                console.log(res)
                if (res.data != null) {
                    self.setData({
                      jieguoList:res.data.list
                    })
                }
              }
            })
          }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})